AWSOIDC: Collect required vpcs and its subnets for use in web UI#35930
AWSOIDC: Collect required vpcs and its subnets for use in web UI#35930
Conversation
6802164 to
0a8d2c4
Compare
|
The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with |
marcoandredinis
left a comment
There was a problem hiding this comment.
I still want to pass again, specially on the logic where we remove the VPCs
I think it's ok, but I need fresh eyes for this 😅
There was a problem hiding this comment.
We discussed this over slack, but this might not return the expected DB Services while the deployed version is <14.2.4
There was a problem hiding this comment.
are you suggesting that i remove it? (or just a FYI during testing?)
There was a problem hiding this comment.
FYI during testing.
I will try to create a dev build and maybe we can use that during our tests
It will be based on the current v14 branch which includes the new label
There was a problem hiding this comment.
You can hard-code the following version if you want to check for the label
teleportVersionTag := "14.2.5-dev.marco.2" Example:
$ tctl get db_services
kind: db_service
metadata:
expires: "2023-12-21T15:44:50.327704669Z"
id: 1703172890371535865
labels:
teleport.dev/awsoidc-agent: "true"
name: 05c13b7c-ed93-42de-9f43-753c1afc08f2
revision: fba61218-27ea-45c9-ad81-3ff2384a7c1c
spec:
resources:
- aws: {}
labels:
account-id: "278576220453"
region: us-east-1
vpc-id: vpc-092abc
version: v1There was a problem hiding this comment.
worked great 👍
lisakim ~/gravitational/teleport/e/build [master] $ ./tctl get db_services
kind: db_service
metadata:
expires: "2023-12-22T04:55:30Z"
id: 1703218345695400557
labels:
teleport.dev/awsoidc-agent: "true"
name: 9cdde9be-9bd5-4c12-b203-363df6059e5c
spec:
resources:
- aws: {}
labels:
account-id: "278576220453"
region: us-east-1
vpc-id: vpc-02149278b986b6f83
version: v1
---
kind: db_service
metadata:
expires: "2023-12-22T04:55:14Z"
id: 1703218339966369543
labels:
teleport.dev/awsoidc-agent: "true"
name: fb7abf52-a70b-4253-849a-da7ebe1cb92d
spec:
resources:
- aws: {}
labels:
account-id: "278576220453"
region: us-east-1
vpc-id: vpc-092c26a0e0e802e92
version: v1
eb56d8b to
0885e70
Compare
marcoandredinis
left a comment
There was a problem hiding this comment.
Just left some comments
There was a problem hiding this comment.
FYI during testing.
I will try to create a dev build and maybe we can use that during our tests
It will be based on the current v14 branch which includes the new label
There was a problem hiding this comment.
I would do some assumptions here: we are only interested in the DatabaseServices deployed by us, which have a known configuration.
We should only have a single ResourceMatcher with non-empty Label set, and each Label must have a single LabelValue.
This should allow us to simplify the multiple for loops we have right now.
| // Start looking for db service matches. | |
| wantLabels := map[string][]string{ | |
| types.DiscoveryLabelAccountID: {}, | |
| types.DiscoveryLabelRegion: {}, | |
| types.DiscoveryLabelVPCID: {}, | |
| } | |
| for _, svc := range fetchedDbSvcs { | |
| // Create a lookup table of labels for easier matching. | |
| labelLookup := map[string][]string{} | |
| for _, matcher := range svc.GetResourceMatchers() { | |
| for key, newVals := range *matcher.Labels { | |
| if existingVals, ok := labelLookup[key]; ok { | |
| labelLookup[key] = append(existingVals, newVals...) | |
| continue | |
| } | |
| labelLookup[key] = newVals | |
| } | |
| } | |
| // Do an exact match, b/c other labels may not match. | |
| if len(labelLookup) != len(wantLabels) { | |
| continue | |
| } | |
| // Match labels contains the keys we are looking for. | |
| matchedLabelKeys := true | |
| for key := range wantLabels { | |
| vals, found := labelLookup[key] | |
| if !found { | |
| matchedLabelKeys = false | |
| break | |
| } | |
| wantLabels[key] = vals | |
| } | |
| if matchedLabelKeys && | |
| slices.Contains(wantLabels[types.DiscoveryLabelAccountID], req.AccountID) && | |
| slices.Contains(wantLabels[types.DiscoveryLabelRegion], req.Region) { | |
| // Delete found vpcs | |
| vpcs := wantLabels[types.DiscoveryLabelVPCID] | |
| for _, vpc := range vpcs { | |
| delete(vpcLookup, vpc) | |
| } | |
| } | |
| } | |
| for _, svc := range fetchedDbSvcs { | |
| if len(svc.GetResourceMatchers()) != 1 || svc.GetResourceMatchers()[0].Labels == nil { | |
| continue | |
| } | |
| labelMatcher := *svc.GetResourceMatchers()[0].Labels | |
| if len(labelMatcher) != 3 { | |
| continue | |
| } | |
| if slices.Compare(labelMatcher[types.DiscoveryLabelAccountID], []string{req.AccountID}) != 0 { | |
| continue | |
| } | |
| if slices.Compare(labelMatcher[types.DiscoveryLabelRegion], []string{req.Region}) != 0 { | |
| continue | |
| } | |
| if len(labelMatcher[types.DiscoveryLabelVPCID]) != 1 { | |
| continue | |
| } | |
| delete(vpcLookup, labelMatcher[types.DiscoveryLabelVPCID][0]) | |
| } |
Tests are failing with this change, but that's because we have multiple ResourceMatchers on the DatabaseServices configuration we created
There was a problem hiding this comment.
I think we should add more information about what this endpoint does and where it is used.
0885e70 to
43e099f
Compare
43e099f to
aacc1af
Compare
|
friendly ping @strideynet @EdwardDowling |
| func stringPointer(s string) *string { | ||
| return &s | ||
| } |
There was a problem hiding this comment.
💅
I think we should use aws.String() instead.
I used this method in the past, but given that it was only being used for AWS Types, I converted most of them to just use the auxiliary method from the AWS package
| } | ||
| } | ||
|
|
||
| func TestAWSOIDCRequiredVPCSHelper(t *testing.T) { |
There was a problem hiding this comment.
Could these tests be t.Parallel() ?
part of #35434
Web UI requires to get a map of missing vpc and its subnets so that
auto-deploystep can deploy services for the missing vpcs. If there are no missing vpcs, then user can skip theauto-deployscreen.Here is overview:
fargate/ecslabel